<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>VRD后台管理页面</title>

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        header .col-md-3{background-color: #3a4144}
        header .col-md-9{background-color: #282d2f}
        header>div>div{height: 50px}
        section .col-md-3{background-color: #282d2f;
            padding: 100px 50px;
        }
        section .col-md-9{background-color: #3a4144}
        section>div>div{height: 1000px}
        .panel-default{background-color: rgba(0,0,0,0);
        border: 0;
        color: #eee;}
        .panel-default>.panel-heading{background-color: rgba(0,0,0,0)}
        #accordion a{
            color: #eee;
        }
        tr>th{
            text-align: center;
        }

    </style>
</head>
<body>
<header>
    <div class="row" >
        <div class="col-md-3">
            <a href="/">
                <img style="margin-left: 20px" src="http://www.vrd.net.cn/vrd/images/logo.png" alt="">
            </a>
        </div>
        <div class="col-md-9" style="color: #eee;line-height: 50px">
            <span class="pull-right" style="font-size:20px ">
                <span>{{user.nick}}欢迎你</span>
                <a href="" @click="logout()">退出登录</a>
            </span>
        </div>
    </div>
</header>
<section>
    <div class="row">
        <div class="col-md-3">
            <!--折叠开始-->
            <div class="panel-group" id="accordion">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="fa fa-user-circle-o" data-toggle="collapse" data-parent="#accordion"
                               href="#collapseOne">
                                分类管理
                            </a>
                        </h4>
                    </div>
                    <div id="collapseOne" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <ul style="list-style-type: none">
                                <li><a href="/admin.html">分类列表</a></li>
                                <li><a href="#" @click="add()">添加分类</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="fa fa-institution" data-toggle="collapse" data-parent="#accordion"
                               href="#collapseTwo">
                                作品管理
                            </a>
                        </h4>
                    </div>
                    <div id="collapseTwo" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul style="list-style-type: none">
                                <li><a href="/admin-product.html">作品列表</a></li>
                                <li><a href="/send.html">添加作品</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="fa fa-photo" data-toggle="collapse" data-parent="#accordion"
                               href="#collapseThree">
                                轮播图管理
                            </a>
                        </h4>
                    </div>
                    <div id="collapseThree" class="panel-collapse collapse">
                        <div class="panel-body">
                            <ul style="list-style-type: none">
                                <li><a href="/admin-banner.html">轮播图列表</a></li>
                                <li><a href="">添加轮播图</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <!--折叠结束-->
        </div>
        <div class="col-md-9"  style="color: #eee">
            <h2 style="color: #ffc600" class="page-header">欢迎访问VRD后台管理系统</h2>
            <table border="1" width="70%" style="text-align:center">
                <caption>分类列表</caption>
                <tr>
                    <th>序号</th>
                    <th>分类名称</th>
                    <th>操作</th>
                </tr>
                <tr v-for=" (c,i) in c_arr">
                    <td>{{i+1}}</td>
                    <td>{{c.name}}</td>
                    <td>
                        <a href="#" @click="del(c.id)">删除</a>
                        <a href="#" @click="delAll(c.id)">删除所有</a>
                    </td>
                </tr>
            </table>

        </div>
        </div>
</section>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    let vm =new Vue({
        el:"header",
        data:{
            user:{}
        },
        created:function () {
                axios.get("/checkLogin").then(function (response) {
                    if (response.data==""){
                        alert("请先登录！");
                        location.href="/login.html";
                    }else {
                        vm.user=response.data;
                    }

                })

            },
        methods:{
            logout:function () {
                if (confirm("您确定要退出吗？"))
                axios.get("/logout").then(function () {
                    location.href="/";
                })

            }
        }

    })
    let section_vm=new Vue({
        el:"section",
        data: {
            c_arr:[]
        },
        created:function () {
            axios.get("/category/select").then(function (response) {
                section_vm.c_arr=response.data;

            })

        },
        methods: {
            del:function (id) {
                if (confirm("您确定删除吗？")){
                    axios.get("/category/delete?id="+id).then(function () {
                        location.reload();

                    })
                }
            },
            add:function () {
                let name=prompt("请输入添加的分类名称");
                if (name!=null){
                    axios.get("/category/insert?name="+name).then(function () {
                        alert("添加完成！");
                        location.reload();
                    })

                }
            },
            delAll:function (id) {
                if (confirm("您确认删除分类所有作品吗？")){
                    axios.get("/category/deleteAll?id="+id).then(function (response) {
                        alert(response.data);
                        location.reload();
                    })
                }
            }
        }
    })
</script>
</body>
</html>